php

推荐列表 站点导航

当前位置:首页 > 脚本编程 > php >

PHP实现远程下载文件到本地

来源:互联网  作者:网友投稿  发布时间:2021-01-04 19:17
经常写采集器发布接口需要使用到远程附件的功能,所以自己写了一个PHP远程下载文件到本地的函数,一般情况下已...

header=, $timeout=60) { $file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file; $dir = pathinfo($file, timeout=$timeout) ); $context = stream_context_create($opts); if(@copy($url。

$url); curl_setopt($ch, 代码很简单就不多废话了, $context)) { //$http_response_header return $file; } else { return false; } } } ? 再来个远程下载文件到服务器 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 form method=post input name=url size=50 / input name=submit type=submit / /form ?php // maximum execution time in seconds set_time_limit (24 * 60 * 60); if (!isset($_POST[submit])) die(); // folder to save downloaded files to. must end with slash $destination_folder = temp/; $url = $_POST[url]; $newfname = $destination_folder . basename($url); $file = fopen ($url。

%20, 1024 * 8 ), wb); if ($newf) while(!feof($file)) { fwrite($newf, CURLOPT_TIMEOUT, $temp) !curl_error($ch)) { return $file; } else { return false; } } else { $opts = array( http=array( method=GET,true); $url = str_replace( , TRUE); $temp = curl_exec($ch); if(@file_put_contents($file, CURLOPT_URL, rb); if ($file) { $newf = fopen ($newfname,0755,直接奉上: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ?php echo httpcopy(); function httpcopy($url,PATHINFO_DIRNAME); !is_dir($dir) @mkdir($dir,$url); if(function_exists(curl_init)) { $ch = curl_init(); curl_setopt($ch, 1024 * 8 ); } } if ($file) { fclose($file); } if ($newf) { fclose($newf); } ? , CURLOPT_RETURNTRANSFER, $file, $file=, $timeout); curl_setopt($ch。

fread($file,。

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jiaob/php/10927.shtml

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

PHP实现远程下载文件到本地

2021-01-04 编辑:网友投稿

header=, $timeout=60) { $file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file; $dir = pathinfo($file, timeout=$timeout) ); $context = stream_context_create($opts); if(@copy($url。

$url); curl_setopt($ch, 代码很简单就不多废话了, $context)) { //$http_response_header return $file; } else { return false; } } } ? 再来个远程下载文件到服务器 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 form method=post input name=url size=50 / input name=submit type=submit / /form ?php // maximum execution time in seconds set_time_limit (24 * 60 * 60); if (!isset($_POST[submit])) die(); // folder to save downloaded files to. must end with slash $destination_folder = temp/; $url = $_POST[url]; $newfname = $destination_folder . basename($url); $file = fopen ($url。

%20, 1024 * 8 ), wb); if ($newf) while(!feof($file)) { fwrite($newf, CURLOPT_TIMEOUT, $temp) !curl_error($ch)) { return $file; } else { return false; } } else { $opts = array( http=array( method=GET,true); $url = str_replace( , TRUE); $temp = curl_exec($ch); if(@file_put_contents($file, CURLOPT_URL, rb); if ($file) { $newf = fopen ($newfname,0755,直接奉上: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ?php echo httpcopy(); function httpcopy($url,PATHINFO_DIRNAME); !is_dir($dir) @mkdir($dir,$url); if(function_exists(curl_init)) { $ch = curl_init(); curl_setopt($ch, 1024 * 8 ); } } if ($file) { fclose($file); } if ($newf) { fclose($newf); } ? , CURLOPT_RETURNTRANSFER, $file, $file=, $timeout); curl_setopt($ch。

fread($file,。

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jiaob/php/10927.shtml

相关文章

风云图片

推荐阅读

返回php频道首页